<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperPath}">
    <resultMap id="BaseResultMap" type="${entityPath}">
        <#list filedList as  filed>
            <#if "${filed.idFiled}"=="1">
                <id column ="${filed.column}" jdbcType="${filed.dbType}" property="${filed.name}" />
            <#else>
                <result column="${filed.column}" jdbcType="${filed.dbType}" property="${filed.name}" />
            </#if>
        </#list>
    </resultMap>

    <insert id="insertSelective" keyColumn="${idColumn}" keyProperty="${idFiled}" useGeneratedKeys="true" parameterType="${entityPath}">>
        INSERT INTO ${table} <include refid= "insertSelectiveColumn"></include> <include refid= "insertSelectiveValue"></include>
    </insert>

    <sql id="columns">
        <#list filedList as  filed>
           <#if filed_index != 0>
                ,
           </#if>
           ${filed.column}
        </#list>
    </sql>

    <sql id="insert_columns">
         <#list filedList as  filed>
           <#if filed_index != 0>
                ,
           </#if>
           ${filed.column}
        </#list>
    </sql>

    <sql id="insert_values">
          <#list filedList as  filed>
           <#if filed_index != 0>
                ,
           </#if>
           ${r"#{"}${filed.name}${r"}"}
          </#list>
    </sql>

    <sql id="insertSelectiveColumn">
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list filedList as  filed>
               <if test="null!=${filed.name}">
                   ${filed.column},
               </if>
            </#list>
        </trim>
    </sql>

    <sql id="insertSelectiveValue">
        <trim prefix="values (" suffix=")" suffixOverrides=",">
             <#list filedList as  filed>
                  <if test="null!=${filed.name}">
                      ${r"#{"}${filed.name},jdbcType=${filed.dbType}${r"}"},
                  </if>
             </#list>
        </trim>
    </sql>

    <sql id="updateByPrimaryKeySelectiveSql">
        <set>
             <#list filedList as  filed>
                  <if test="null!=${filed.name}">
                     ${filed.column} = ${r"#{"}${filed.name},jdbcType=${filed.dbType}${r"}"},
                  </if>
             </#list>
        </set>
    </sql>

   <sql id="where">
         <#list filedList as  filed>
              <if test="null!=${filed.name}">
                 AND ${filed.column} = ${r"#{"}${filed.name},jdbcType=${filed.dbType}${r"}"},
              </if>
         </#list>
   </sql>
</mapper>